import { ArticleComment, ArticleDetail } from "@/types/data";
import { ArticleAction } from "@/types/store";
type ArticleState = {
  // 文章详情
  detail: ArticleDetail;
  comment: ArticleComment;
};
const initialState = {
  detail: {},
  // 评论列表
  comment: {
    results: [] as ArticleComment["results"],
  },
} as ArticleState;

const article = (state = initialState, action: ArticleAction): ArticleState => {
  if (action.type === "article/get") {
    return {
      ...state,
      detail: action.payload,
    };
  }
  if (action.type === "article/updateInfo") {
    return {
      ...state,
      detail: {
        ...state.detail,
        [action.payload.name]: action.payload.value,
      },
    };
  }
  return state;
};

export default article;
